﻿using ObjectBakery;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ObjectBakery.Tests.TestDoubles;
using System.Collections.Generic;
using System.Text;
using System.IO;
using ObjectBakery.Helpers;
using System.Text.RegularExpressions;
namespace ObjectBakery.Tests
{
    
    
    /// <summary>
    ///This is a test class for ObjectFactoryTest and is intended
    ///to contain all ObjectFactoryTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ObjectFactoryTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion







        /// <summary>
        ///A test for Build
        ///</summary>
        [TestMethod()]
        [DeploymentItem(@".\Asset.cs")]
        [DeploymentItem(@".\Product.cs")]
        public void CanBuild()
        {
            Language language = Language.CSharp;
            ScriptObjectFactory objectFactory = new ScriptObjectFactory(language);

            string strAssetClass = File.ReadAllText(@".\Asset.cs");
            string strProductClass = File.ReadAllText(@".\Product.cs");

            List<string> fullQualifiedTypeNames = new List<string>( 
                new string[]{ "ObjectBakery.Tests.TestDoubles.Asset", "ObjectBakery.Tests.TestDoubles.Product" } );


            string strSource = strProductClass;
           
            string unionedWhole = new StringHelper().PrepareSourceSpool(
                                        new List<string>( 
                                            new string[]{ strAssetClass, strProductClass }), 
                                                Language.CSharp);

            var entities = objectFactory.Build(fullQualifiedTypeNames, unionedWhole);

            //These types are not the same but their fqNames match exactly
            IEnumerator<object> enumerator = entities.GetEnumerator();
            
            while (enumerator.MoveNext())
            {
                var instance = enumerator.Current;
                Assert.IsTrue(fullQualifiedTypeNames.Contains(instance.GetType().ToString()));
            }
        }



    }
}
